<?php 
	if (isset($_GET['id_group']) && isset($_GET['type']) && $_GET['type'] == 'get_mail')
	{
		require_once('Class/connexionDB.Class.php');

		$db 			= new connexionDB();
		$mail_adress 	= array();


		$result = $db->getMailAssociatedToIdGroup('%'.$_GET['id_group'].'%');

		foreach ($result as $key => $value) 
		{
			$mail_adress[] = $value['mail'];
		}
		echo implode('; ', $mail_adress);
	}

	if (isset($_GET['type']) && $_GET['type'] == 'up_mail' && isset($_GET['mail_content']) && $_GET['mail_content'] != '' && isset($_GET['id_group']))
	{
		require_once('Class/connexionDB.Class.php');

		$db 		= new connexionDB();
		$str_mail 	= str_replace(' ', '', $_GET['mail_content']);
		$mail_array = explode(';', $str_mail);

		$db->deletedRowAssociated($_GET['id_group']);
		foreach ($mail_array as $value)
		{
			if ($value != '')
			{
				$db->updateAssocitedMailToGroup($value, $_GET['id_group']);
			}
		}
	}

	if (isset($_GET['type']) && $_GET['type'] == 'up_mail_content' && isset($_GET['send_to']) && isset($_GET['new_subject']) && isset($_GET['mail_content']))
	{
		require_once('Class/connexionDB.Class.php');

		$db = new connexionDB();
		$db->updateMail(	$_GET['send_to'], 
						 	$_GET['new_subject'], 
						 	$_GET['mail_content']);
	}
?>